package com.frogs.ucenter.v1.controller;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;

import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;

import com.frogs.system.web.api.response.FailResponse;
import com.frogs.system.web.api.response.Response;
import com.frogs.system.web.exception.AppBaseException;
import com.frogs.ucenter.v1.request.DiseaseInfoListRequest;
import com.frogs.ucenter.v1.request.DiseaseInfoMergeRequest;
import com.frogs.ucenter.v1.request.IrritabilityInfoDeleteRequest;
import com.frogs.ucenter.v1.request.IrritabilityInfoListRequest;
import com.frogs.ucenter.v1.request.IrritabilityInfoMegerRequest;
import com.frogs.ucenter.v1.request.LifeWayListRequest;
import com.frogs.ucenter.v1.request.LifeWayMergeRequest;
import com.frogs.ucenter.v1.request.MedicalHistoryDeleteRequest;
import com.frogs.ucenter.v1.request.MedicalHistoryListRequest;
import com.frogs.ucenter.v1.request.MedicalHistoryMergeRequest;
import com.frogs.ucenter.v1.service.DiseaseInfoService;
import com.frogs.ucenter.v1.service.IrritabilityInfoService;
import com.frogs.ucenter.v1.service.LifeWayService;
import com.frogs.ucenter.v1.service.MedicalHistoryService;
import com.frogs.ucenter.v1.util.ApiConstants;

/**
 * 健康档案
 *
 * @author zhuqiang
 * @version 2015年7月22日 - 上午10:12:42
 */
@Controller(ApiConstants.VERSION+"healthRecordController")
@RequestMapping("/"+ApiConstants.VERSION)
public class HealthRecordController {

	private static final String ROOT = "/health";
	private static final String HEALTH_IRRITABILITY_MERGE = ROOT + "/irritability/merge";
	private static final String HEALTH_IRRITABILITY_LIST = ROOT + "/irritability/list";
	private static final String HEALTH_IRRITABILITY_DELETE = ROOT + "/irritability/delete";

	private static final String HEALTH_MEDICAL_MERGE = ROOT + "/medicalHistory/merge";
	private static final String HEALTH_MEDICAL_LIST = ROOT + "/medicalHistory/list";
	private static final String HEALTH_MEDICAL_DELETE = ROOT + "/medicalHistory/delete";
	
	private static final String HEALTH_LIFEWAY_MERGE = ROOT + "/lifeWay/merge";
	private static final String HEALTH_LIFEWAY_LIST = ROOT + "/lifeWay/list";
	
	private static final String HEALTH_DISEASEINFO_MERGE = ROOT + "/diseaseInfo/merge";
	private static final String HEALTH_DISEASEINFO_LIST = ROOT + "/diseaseInfo/list";
	private static final String HEALTH_DISEASEINFO_DELETE = ROOT + "/diseaseInfo/delete";

	
	@Resource(name=ApiConstants.VERSION + "irritabilityInfoService")
	private IrritabilityInfoService irritabilityInfoService;
	
	@Resource(name=ApiConstants.VERSION + "medicalHistoryService")
	private MedicalHistoryService medicalHistoryService;
	
	@Resource(name=ApiConstants.VERSION + "lifeWayService")
	private LifeWayService lifeWayService;
	
	@Resource(name=ApiConstants.VERSION + "diseaseInfoService")
	private DiseaseInfoService diseaseInfoService;
	
	/**
	 * 添加或修改过敏档案
	 * @param request
	 * @return
	 */
	@RequestMapping(HEALTH_IRRITABILITY_MERGE)
	public Response irritabilityInfoMerge(HttpServletRequest request){
		Response response;
		try {
			IrritabilityInfoMegerRequest irMergeRequest = new IrritabilityInfoMegerRequest();
			irMergeRequest.parse(request);
			response = irritabilityInfoService.mergeRecord(irMergeRequest);
		} catch (Exception e) {
			response = new FailResponse();
			if (e instanceof AppBaseException) {
				response.setTip(e.getMessage());
			} else {
				response.setTip("errro message" + e.getMessage());
			}
		}
		return response;
	}
	
	/**
	 * 显示过敏档案
	 * @param request
	 * @return
	 */
	@RequestMapping(HEALTH_IRRITABILITY_LIST)
	public Response irritabilityInfoList(HttpServletRequest request){
		Response response;
		try{
			IrritabilityInfoListRequest irListRequest = new IrritabilityInfoListRequest();
			irListRequest.parse(request);
			response = irritabilityInfoService.listRecord(irListRequest);
		} catch (Exception e) {
			response = new FailResponse();
			if (e instanceof AppBaseException) {
				response.setTip(e.getMessage());
			} else {
				response.setTip("errro message" + e.getMessage());
			}
		}
		return response;
	}
	
	/**
	 * 删除过敏档案(逻辑删除)
	 * @param request
	 * @return
	 */
	@RequestMapping(HEALTH_IRRITABILITY_DELETE)
	public Response irritabilityInfoDelete(HttpServletRequest request){
		Response response;
		try {
			IrritabilityInfoDeleteRequest irDeleteRequest = new IrritabilityInfoDeleteRequest();
			irDeleteRequest.parse(request);
			response = irritabilityInfoService.deleteRecord(irDeleteRequest);
		} catch (Exception e) {
			response = new FailResponse();
			if (e instanceof AppBaseException) {
				response.setTip(e.getMessage());
			} else {
				response.setTip("errro message" + e.getMessage());
			}
		}
		return response;
	}
	
	/**
	 * 添加或修改病历管理档案
	 * @param request
	 * @return
	 */
	@RequestMapping(HEALTH_MEDICAL_MERGE)
	public Response medicalHistoryMerge(HttpServletRequest request){
		Response response;
		try {
			MedicalHistoryMergeRequest mhMergeRequest = new MedicalHistoryMergeRequest();
			mhMergeRequest.parse(request);
			response = medicalHistoryService.mergeRecord(mhMergeRequest);
		} catch (Exception e) {
			response = new FailResponse();
			if (e instanceof AppBaseException) {
				response.setTip(e.getMessage());
			} else {
				response.setTip("errro message" + e.getMessage());
			}
		}
		return response;
	}
	
	/**
	 * 显示病历管理档案列表
	 * @param request
	 * @return
	 */
	@RequestMapping(HEALTH_MEDICAL_LIST)
	public Response medicalHistoryList(HttpServletRequest request){
		Response response;
		try {
			MedicalHistoryListRequest mhListRequest = new MedicalHistoryListRequest();
			mhListRequest.parse(request);
			response = medicalHistoryService.listRecord(mhListRequest);
		} catch (Exception e) {
			response = new FailResponse();
			if (e instanceof AppBaseException) {
				response.setTip(e.getMessage());
			} else {
				response.setTip("errro message" + e.getMessage());
			}
		}
		return response;
	}
	
	/**
	 * 删除病历管理档案(逻辑删除)
	 */
	@RequestMapping(HEALTH_MEDICAL_DELETE)
	public Response medicalHistoryDelete(HttpServletRequest request){
		Response response;
		try {
			MedicalHistoryDeleteRequest mhDeleteRequest = new MedicalHistoryDeleteRequest();
			mhDeleteRequest.parse(request);
			response = medicalHistoryService.deleteRecord(mhDeleteRequest);
		} catch (Exception e) {
			response = new FailResponse();
			if (e instanceof AppBaseException) {
				response.setTip(e.getMessage());
			} else {
				response.setTip("errro message" + e.getMessage());
			}
		}
		return response;
	}
	
	/**
	 * 添加或修改生活方式档案
	 */
	@RequestMapping(HEALTH_LIFEWAY_MERGE)
	public Response lifeWayMerge(HttpServletRequest request){
		Response response;
		try{
			LifeWayMergeRequest lwMergeRequest = new LifeWayMergeRequest();
			lwMergeRequest.parse(request);
			response = lifeWayService.mergeRecord(lwMergeRequest);
		}catch(Exception e){
			response = new FailResponse();
			if (e instanceof AppBaseException) {
				response.setTip(e.getMessage());
			} else {
				response.setTip("error message" + e.getMessage());
			}
		}
		return response;
	}
	
	/**
	 * 查看生活方式档案
	 */
	@RequestMapping(HEALTH_LIFEWAY_LIST)
	public Response lifeWayList(HttpServletRequest request){
		Response response;
		try {
			LifeWayListRequest lwListRequest = new LifeWayListRequest();
			lwListRequest.parse(request);
			response = lifeWayService.listRecord(lwListRequest);
		} catch (Exception e) {
			response = new FailResponse();
			if (e instanceof AppBaseException) {
				response.setTip(e.getMessage());
			} else {
				response.setTip("errro message" + e.getMessage());
			}
		}
		return response;
	}
	
	/**
	 * 添加或修改疾病档案
	 */
	@RequestMapping(HEALTH_DISEASEINFO_MERGE)
	public Response diseaseInfoMerge(HttpServletRequest request){
		Response response;
		try {
			DiseaseInfoMergeRequest diMergeRequest = new DiseaseInfoMergeRequest();
			diMergeRequest.parse(request);
			response = diseaseInfoService.mergeRecord(diMergeRequest);
		} catch (Exception e) {
			response = new FailResponse();
			if (e instanceof AppBaseException) {
				response.setTip(e.getMessage());
			} else {
				response.setTip("errro message" + e.getMessage());
			}
		}
		return response;
	}
	
	/**
	 * 显示疾病档案列表
	 */
	@RequestMapping(HEALTH_DISEASEINFO_LIST)
	public Response diseaseInfoList(HttpServletRequest request){
		Response response;
		try {
			DiseaseInfoListRequest diListRequest = new DiseaseInfoListRequest();
			diListRequest.parse(request);
			response = diseaseInfoService.listRecord(diListRequest);
		} catch (Exception e) {
			response = new FailResponse();
			if (e instanceof AppBaseException) {
				response.setTip(e.getMessage());
			} else {
				response.setTip("errro message" + e.getMessage());
			}
		}
		return response;
	}
	
	/**
	 * 删除疾病档案(逻辑删除)
	 */
	@RequestMapping(HEALTH_DISEASEINFO_DELETE)
	public Response diseaseInfoDelete(HttpServletRequest request){
		Response response;
		try {
			DiseaseInfoMergeRequest diMergeRequest = new DiseaseInfoMergeRequest();
			diMergeRequest.parse(request);
			response = diseaseInfoService.deleteRecord(diMergeRequest);
		} catch (Exception e) {
			response = new FailResponse();
			if (e instanceof AppBaseException) {
				response.setTip(e.getMessage());
			} else {
				response.setTip("errro message" + e.getMessage());
			}
		}
		return response;
	}
}
